﻿<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <title>叩丁狼CRM(演示版)</title>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <#include "../common/head.ftl"/>
    <link rel="stylesheet" href="/css/core.css"/>
</head>
<body>
<#assign menu="salary"/>
<div class="container " style="margin-top: 20px">
    <#include "../common/welcome.ftl"/>
    <div class="row">

        <#include "../common/menu.ftl"/>

        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">工资管理</h1>
                </div>
            </div>

            <div class="row">
                <div class="col-sm-4">
                    <ul id="menu" class="list-group">
                        <li class="list-group-item">
                            <a href="javascript:" data-toggle="collapse">
                                <span>员工列表管理</span>
                            </a>
                            <ul class="in" id="employees">
                                <#list employeeList as entity>
                                    <li data-did="${(entity.id)!}">
                                        <a  role="button">${(entity.name)!}</a>
                                    </li>
                                </#list>
                            </ul>
                        </li>
                    </ul>
                </div>


                <div class="col-sm-8">
                    <form class="form-inline" id="searchForm" action="/salary/list.do" method="post">
                        <input type="hidden" name="currentPage" id="currentPage" value="1">
                        <input type="hidden" id="parentId" name="parentId" value="${qo.parentId}">
                    </form>

                <#if pageInfo??>
                        <a  class="btn btn-success inputBtn">
                            <span class="glyphicon glyphicon-plus"></span> 添加
                        </a>
                    <table class="table table-striped table-hover" >
                        <tr>
                            <th>序号</th>
                            <th>年份</th>
                            <th>月份</th>
                            <th>员工</th>
                            <th>工资</th>
                            <th>操作</th>
                        </tr>
                        <#list pageInfo.list as entity>
                        <tr>
                            <td>${entity_index + 1}</td>
                            <td>${entity.year}</td>
                            <td>${entity.month}</td>
                            <td>${entity.employee.name}</td>
                            <td>${entity.money}</td>
                             <td>
                                 <a role="button" data-json='${entity.json}' class="btn btn-info btn-xs inputBtn">
                                     <span  class="glyphicon glyphicon-pencil"></span> 编辑
                                 </a>
                             </td>
                        </tr>
                        </#list>
                    </table>
                    <#include "../common/page.ftl"/>
                 </#if>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">新增/编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/salary/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" name="id"/>
                    <input type="hidden" name="employee.id"/>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">年份：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="year" placeholder="请输入年份">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">月份：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="month" placeholder="请输入月份">
                        </div>
                    </div>
                    <div class="form-group" >
                        <label class="col-sm-3 control-label">员工名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name" readonly="true">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">工资：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="money" placeholder="请输入工资">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary saveOrUpdateBtn">保存</button>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        //菜单回显
        var select =  $("li[data-did=${qo.parentId}]").addClass("active");
        console.log(select);
        var param = {"id":select.data("did"),"name":select.find("a").html()};
        console.log(param);


        $(".saveOrUpdateBtn").click(function () {
            $("#editForm").submit();
        });

        $("#editForm").ajaxForm(function () {

        });



        $("li[data-did]").click(function () {
            var parent = $(this).data("did");
            $("#parentId").val(parent);
            $("#searchForm").submit();
        });



        $(".inputBtn").click(function () {
            $("#editForm input").val("");
            $("#editForm input[name='employee.id']").val(param.id);
            $("#editForm input[name='name']").val(param.name);
            var json = $(this).data("json");
            console.log(json);
            if(json){
                $("#editForm input[name='id']").val(json.id);
                $("#editForm input[name='year']").val(json.year);
                $("#editForm input[name='month']").val(json.month);
                $("#editForm input[name='money']").val(json.money);
            }
            $("#myModal").modal("show");
        });
    });

</script>

</body>
</html>
